package com.iot08.api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.filter.FormContentFilter;

/**
 * Import(FormContentFilter.class)
 * 将HTTP的PUT、PATCH、DELETE请求中的form data转化，并暴露给Servlet的“请求参数”。
 * 默认情况下，Servlet规范仅仅要求POST请求转化form data; 导入FormContentFilter即可。
 * 如果不需要处理DELETE请求，HttpPutFormContentFilter也可以，但是已废弃
 *
 * @version 1.0
 * @author: Rock
 * @time: 2021/2/26 15:42
 */
@Import(FormContentFilter.class)
@EnableAsync
//@EnableScheduling
@SpringBootApplication(scanBasePackages = "com.iot08")
public class WebApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebApiApplication.class, args);
    }

    /**
     * 允许请求中含有字符[]{}
     *
     * @param
     * @time: 2021/3/5 16:09
     * @author: Rock
     * @version 1.0
     */
    @Bean
    public TomcatServletWebServerFactory tomcatServletWebServerFactory() {
        // 修改内置的 tomcat 容器配置
        TomcatServletWebServerFactory tomcatServlet = new TomcatServletWebServerFactory();
        tomcatServlet.addConnectorCustomizers(
                (TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "[]{}")
        );
        return tomcatServlet;
    }

}
